﻿@{
    ViewBag.Title = " 菜单列表";
    Layout = "~/Views/Shared/_Layout_Easyui.cshtml";
    //Layout = null;
}
<div id="menu_list_grid"></div>
<div id="menu_list_window_create"></div>
@section Scripts
{
    <script type="text/javascript">
        Oneworks.CreatePage('MenuList', {
            settings: {
                gridurl: '/Models/datagrid.json',
                createurl: '/Menu/Create'
            },
            controls: {
                gird: $('#menu_list_grid'),
                createwindow: $('#menu_list_window_create')
            },
            events: {
                onLoadCreate: function () {
                    var page = Oneworks.page, create = page['MenuCreate'], list = page['MenuList'];
                    create.events.onClose = list.events.onCloseCreate;
                    create.events.onSuccess = list.events.onCreateSuccess;
                    create.events.onFailure = list.events.onCreateFailure;
                },
                onOpenCreate: function () {
                    Oneworks.page['MenuList'].controls.createwindow.window('open');
                },
                onCloseCreate: function () {
                    Oneworks.page['MenuList'].controls.createwindow.window('close');
                },
                onCreateSuccess: function () {
                    console.log(arguments[0]);
                    Oneworks.Easyui.alert(arguments[0].Message, function () {
                        Oneworks.Easyui.alert(arguments[0].Result.UserCode);
                    });
                },
                onCreateFailure: function () {
                    Oneworks.Easyui.alert(arguments[0].Message);
                },
            }
        }, function () {
            var that = this,
                controls = that.controls,
                settings = that.settings,
                events = that.events;
            controls.init = function () {
                controls.createwindow.Easyui().window({
                    title: '创建菜单',
                    width: 460,
                    height: 400,
                    href: settings.createurl,
                    closed: true,
                    onLoad: events.onLoadCreate
                });

                controls.gird.datagrid({
                    title: '菜单列表',
                    toolbar: [{
                        text: '搜索',
                        handler: function () { alert('搜索') }
                    }, '-', {
                        text: '添加',
                        handler: function() {
                            controls.createwindow.window('open');
                        }
                    }, '-', {
                        text: '删除',
                        handler: function () { alert('删除') }
                    }, '-', {
                        text: '修改',
                        handler: function () { alert('修改') }
                    }],
                    pagination: true,
                    url: settings.gridurl,
                    method: "GET",
                    fit: true,
                    fitColumns: true,
                    columns: [[
                        { field: 'productid', title: 'productid', width: 100 },
                        { field: 'productname', title: 'productname', width: 100 },
                        { field: 'unitcost', title: 'unitcost', width: 100, align: 'right' }
                    ]]
                });
            };
            events.init = function () {
            };
            controls.init();
            events.init();
        });
    </script>
}
